<template>
    <div class="adjust_from">
        <div class="main_title">
            编辑样本
            <el-tooltip class="item" effect="dark" content="撤销修改" placement="top">
                <i class="el-icon-refresh-left edit_button" @click="cancelGroup2"></i>
            </el-tooltip>
        </div>
        <div class="group_items_div">
            <template v-for="(item, index) in dataList">
                <el-tooltip placement="top">
                    <div slot="content">{{ item.groupTitle }}</div>
                    <div class="items" :class="{ 'is_active': item.ischecked }" @click="changeStatusItem(item)">{{
                        item.groupTitle }}
                    </div>
                </el-tooltip>
            </template>
        </div>
    </div>
</template>

<script>
import { deepClone } from '@/utils';
export default {
    name: 'GenecloudUiGroup2',
    props: {
        group2: {
            type: Array,
            default: () => []
        },
    },
    data() {
        return {
            //样本信息
            dataList: [],
            cancelList: [],
        };
    },
    watch: {
        group2: {
            handler(val, newVal) {
                if (val) {
                    this.dataList = deepClone(val)
                    this.cancelList = deepClone(val)
                }
            },
            immediate: true,
        },
    },
    mounted() {

    },

    methods: {
        changeStatusItem(item) {
            if (item.ischecked) {
                let num = 0
                this.dataList.forEach(item => {
                    console.log(item);
                    if (item.ischecked) {
                        num++
                    }
                })
                if (num < 2) return this.$message.error('至少需要存在一种样本！')
            }
            item.ischecked = !item.ischecked
            this.$emit('changeGroup2Status', this.dataList)
        },
        cancelGroup2() {
            this.dataList = deepClone(this.cancelList)
            this.$emit('changeGroup2Status', this.dataList)
        }
    },
};
</script>

<style lang="scss" scoped>
@import "~@/styles/variables.scss";

.adjust_from {
    padding: 20px 0;

    ::v-deep .el-input__inner {
        height: 35px;
        border-radius: 6px;
    }

    .top_item {
        ::v-deep .el-input__inner {
            border-radius: 0 6px 6px 0;
        }
    }

    ::v-deep .el-button--mini {
        padding: 9px;
        margin-left: 10px;
    }

    ::v-deep .el-select-dropdown__item {
        .select_i {
            &:hover {
                color: red !important;
            }
        }

    }

    ::v-deep .el-dialog__header {
        text-align: center;
        font-weight: 700;
        border-bottom: 1px solid #ccc;
    }

    ::v-deep .el-input-group__prepend {
        padding: 0 8px;
    }

    ::v-deep .el-radio {
        margin-right: 5px;
    }

    .group_items_div {
        display: flex;
        align-content: flex-start;
        flex-wrap: wrap;
        justify-content: flex-start;
        padding: 25px 0 25px 30px;
        width: 100%;
        // height: 200px;
        // overflow-y: auto;

        .items {
            width: 74px;
            height: 30px;
            text-align: center;
            line-height: 26px;
            margin: 0 10px 10px 0;
            background-color: #fff;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            border: 1px solid #ccc;
            color: #666;
            border-radius: 3px;
            cursor: pointer;

            &.is_active {
                border: 2px solid $themeTopToolColor;
            }
        }
    }
}

.main_title {
    font-size: 14px;
    color: #333;
    font-weight: 700;
}

.edit_button {
    cursor: pointer;
    width: 30px;
    height: 30px;
    text-align: center;
    line-height: 30px;

    &:hover {
        background-color: #ccc;
        border-radius: 50%;
    }
}
</style>